﻿using System;
using System.IO;
using System.Runtime.Serialization;

namespace _042_保留实例引用
{
    class Program
    {
        /// <summary>
        /// 本项目没做完，P354页
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            using (FileStream 执行序列化=File.Open("zoomla.xml",FileMode.Create))
            {
                OrderDetails 操作之一 = new OrderDetails
                {
                    ContactName = "Lee",
                    Price = 3.15M,
                    Quantity = 12,
                    Weight = 17.5f
                };

                OrderInfo[] 订单数据 =
                {
                    new OrderInfo
                    {
                        OrderNo=1,
                        BuildTime=new DateTime(2018,3,27),
                        DetailsData=操作之一
                    },
                    new OrderInfo
                    {
                        OrderNo=2,
                        BuildTime=new DateTime(2018,9,2),
                        DetailsData=操作之一
                    }
                };

                DataContractSerializer 输出之后 = new DataContractSerializer(订单数据.GetType());
                输出之后.WriteObject(执行序列化, 订单数据);

            }



        }
    }


    [DataContract]
    public class OrderDetails
    {
        [DataMember]
        public string ContactName { get; set; }
        [DataMember]
        public decimal Price { get; set; }
        [DataMember]
        public int Quantity { get; set; }
        [DataMember]
        public float Weight { get; set; }
    }

    [DataContract]
    public class OrderInfo
    {
        [DataMember]
        public int OrderNo { get; set; }
        [DataMember]
        public DateTime BuildTime { get; set; }
        [DataMember]
        public OrderDetails DetailsData { get; set; }
    }
}
